package org.spark.core.transformations.scala

import org.spark.sparkUtil.SparkScalaContextUtil

/**
  * 功能概述:
  * Datetime:    2020/5/25   19:01
  * Author:   某人的目光
  */
object GroupByKey {
  def main(args: Array[String]): Unit = {
    val sc = SparkScalaContextUtil.getSparkStart("flatMap");
    val scoreList = Array(Tuple2("class1", 80), Tuple2("class2", 75),
      Tuple2("class1", 90), Tuple2("class2", 60))
    val scores = sc.parallelize(scoreList, 1)
    val groupedScores = scores.groupByKey()

    groupedScores.foreach(score => {
      println(score._1);
      score._2.foreach { singleScore => println(singleScore) };
      println("=============================")
    })
  }
}
